using Common;
using Framework;
using UnityEngine;

public class HomePage : View
{
    private Vector2 initPos;
    private RectTransform rect;
    private HomePageItem[] items;

    protected override void Init()
    {
        rect = transform.GetComponent<RectTransform>();
        initPos = rect.anchoredPosition;

        items = GetComponentsInChildren<HomePageItem>();
        foreach (var item in items)
        {
            item.action += LoadScene;
        }
    }

    private void LoadScene(string sceneName)
    {
        TriggerModuleEvent(GlobalEvent.LoadScene, sceneName);
    }

    public void Show()
    {
        rect.anchoredPosition = initPos;
    }

    public void Hide()
    {
        rect.anchoredPosition = new Vector2(100000, 100000);
    }
}
